package thread_base;

import annotation.NotThreadSafe;

// *
// Written by MAX 2024/7/24 16:26
// Note:*
@NotThreadSafe
public class UnsafeSequence {
    private int value;

    public int getNext() {
        return value++;
    }

    public static void main(String[] args) throws InterruptedException {
        UnsafeSequence sequence = new UnsafeSequence();
        Thread t1 = new Thread(() -> System.out.println(Thread.currentThread().getName() + ": " + sequence.getNext()));
        Thread t2 = new Thread(() -> System.out.println(Thread.currentThread().getName() + ": " + sequence.getNext()));

        t1.start();
        t2.start();

        t1.join();
        t2.join();
    }
}
